import Vue from 'vue'
import { getDict, getPermission } from '@requests/dict'

export default {
  namespaced: true,
  state: {},
  mutations: {
    setData(state, payload) {
      Vue.set(state, payload.key, payload.value)
    }
  },
  actions: {
    init(context) {
      getDict().then(res => {
        res.result.forEach(item => {
          context.commit('setData', {
            key: item.field,
            value: item.options.map(x => {
              return {
                name: x.label,
                value: x.value
              }
            })
          })
        })
      })
      getPermission().then(res => {
        context.commit('setData', {
          key: 'permissions',
          value: res.result
        })
      })
    }
  }
}
